#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<string>
using namespace std;
string reverseWords(string s) {
    string rs;
    size_t start = 0;
    for (size_t i = 0; i <= s.size(); i++)
    {
        if (i == s.size() || s[i] == ' ')
        {
            string tmp = s.substr(start, i - start);
            reverse(tmp.begin(), tmp.end());
            rs += tmp;
            if (i != s.size())
                rs += ' ';
            start = i + 1;
        }       
    }
    return rs;
}
int main()
{
    string s = "Let's take LeetCode contest";
    string rs = reverseWords(s);
    cout << rs << endl;
    return 0;
}